# -*- coding: utf-8 -*-
"""
@author:xuyuntao
@time:2021/5/31/031:10:04
@email:xuyuntao@189.cn
"""
import numpy
def getBias(idealValue:numpy.ndarray,freeBias:float=3.0):
    """计算输入理想参考值的偏差矩阵，理想参考值为一维数组，偏差为两行且列数与参考值个数一致的矩阵
    第一行为左偏差，第二行为右偏差
    输入：理想值矩阵，最大偏差
    输出：偏差值矩阵"""
    sortI=numpy.argsort(idealValue)
    bias_tmp=numpy.diff(idealValue[sortI])/2

    bias_left=numpy.zeros(bias_tmp.size+1,dtype=numpy.float64)
    bias_left[sortI[0]]=freeBias
    bias_left[sortI[1:]]=bias_tmp
    bias_right=numpy.zeros(bias_tmp.size+1,dtype=numpy.float64)
    bias_right[sortI[-1]]=freeBias
    bias_right[sortI[0:-1]]=bias_tmp
    bias=numpy.zeros([2,bias_tmp.size+1],dtype=numpy.float64)
    bias[0,:]=bias_left
    bias[1,:]=bias_right
    del bias_tmp,bias_left,bias_right,sortI
    return bias